package com.xuzimian.globaldemo.spring.springmvc.servlet;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

public class MyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是get方法提交");
        resp.setContentType("application/json; charset=utf-8");
        resp.setCharacterEncoding("UTF-8");

        OutputStream out = resp.getOutputStream();
        out.write("{msg: hello,this is  MyServlet doGet response you}".getBytes("UTF-8"));
        out.flush();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是post方法提交");
        resp.setContentType("application/json; charset=utf-8");
        resp.setCharacterEncoding("UTF-8");

        OutputStream out = resp.getOutputStream();
        out.write("{msg: hello,this is  MyServlet doPost response you}".getBytes("UTF-8"));
        out.flush();
    }
}
